package com.daodao.daodaoschedule.application.service;

import com.daodao.daodaoschedule.domain.wechat.RemindEvent;
import com.daodao.daodaoschedule.infrastructure.repository.RemindEventRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author mal
 * @date 2023-02-15 16:07
 */
@Service
@AllArgsConstructor
public class RemindEventServiceImpl implements RemindEventService {

    private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");

    private final RemindEventRepository remindEventRepository;

    @Override
    public String buildRemindInfo() {
        List<RemindEvent> validEventList = remindEventRepository.getValidEventList();
        if (validEventList.isEmpty()) {
            return "";
        }
        StringBuilder remindSb = new StringBuilder();
        for (int i = 0; i < validEventList.size(); i++) {
            RemindEvent remindEvent = validEventList.get(i);
            if (remindSb.length() > 0) {
                remindSb.append(";");
            }
            remindSb.append(i + 1).append(":")
                    .append(dateTimeFormatter.format(remindEvent.getEventDate())).append(",")
                    .append(remindEvent.getEventDesc()).append(",")
                    .append(remindEvent.getRemarks());


        }
        return remindSb.toString();
    }

}
